package com.sgb.kjwl.viewmodel.self.packers;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.self.SelfTeamAlbumEntity;
import com.sgb.kjwl.model.entity.self.WebsiteDeleteEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.packers.SelfTeamAlbumEditActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SelfTeamAlbumEditModel extends BaseViewModel {

    private SelfTeamAlbumEditActivity activity;

    public SelfTeamAlbumEditModel(SelfTeamAlbumEditActivity activity, SelfRepertory repertory) {
        this.activity = activity;
    }

    public void deletePhotoData(List<SelfTeamAlbumEntity> id){

        DialogHelper.showProgressDialog(activity, null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().deleteTeamAlbum(id.get(0)).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    EventBus.getDefault().post("save_photo_data");
                    activity.finish();
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                t.printStackTrace();
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
